package studio.raptor.dispatcher.server;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import studio.raptor.dispatcher.scheduler.ServerSchedulerConfig;
import studio.raptor.dispatcher.server.listeners.DispatcherFailedListener;
import studio.raptor.dispatcher.server.listeners.DispatcherPreparedListener;
import studio.raptor.dispatcher.server.listeners.DispatcherReadyListener;
import studio.raptor.hub.out.HubOutConfig;

/**
 * @author jack
 * @since 1.0
 */
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackageClasses = {DispatcherServiceApplication.class,
    ServerSchedulerConfig.class, HubOutConfig.class})
@EnableAsync
@EnableAspectJAutoProxy
@EnableScheduling
public class DispatcherServiceApplication extends SpringBootServletInitializer {


  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return configureApplication(builder);
  }

  public static void main(String[] args) {
    configureApplication(new SpringApplicationBuilder()).run(args);
  }

  private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
    return builder
        .sources(DispatcherServiceApplication.class)
        .listeners(new DispatcherPreparedListener())
        .listeners(new DispatcherFailedListener())
        .listeners(new DispatcherReadyListener());
  }

}
